﻿using System;
using System.Data;
using System.Configuration;
using System.Web;

using System.Net.Mail;

/// <summary>
/// Descripción breve de iMail
/// </summary>
public class iMail
{
    private string _error;
    public iMail()
    {
        //
        // TODO: Agregar aquí la lógica del constructor
        //
    }
    public string Error {
        get { return _error; }
    }
    public void SendMail(string Mailto, string MailBoby)
    {
        //Builed The MSG
        if (Mailto.Length != 0 && MailBoby.Length!=0)
        {

            System.Net.Mail.MailMessage msg = new System.Net.Mail.MailMessage();
            msg.To.Add(Mailto);

            msg.From = new MailAddress("soporte@intschools.org", "Soporte IntSchools", System.Text.Encoding.UTF8);
            msg.Subject = "Soporte IntSchools";
            msg.SubjectEncoding = System.Text.Encoding.UTF8;
            msg.Body = MailBoby;
            msg.BodyEncoding = System.Text.Encoding.UTF8;
            msg.IsBodyHtml = true;
            msg.Priority = MailPriority.High;

            //Add the Creddentials
            SmtpClient client = new SmtpClient();
            client.Credentials = new System.Net.NetworkCredential("soporte@intschools.org", "3scan");
            client.Port = 25;
            client.Host = "smtp.intschools.org";
            client.EnableSsl = false;
            object userState = msg;
            try
            {
                client.Send(msg);
                _error = "mensaje enviado a " + msg.To.ToString();
            }
            catch (System.Net.Mail.SmtpException ex)
            {
                _error = ex.Message;
            }
        }
    }
}
